import { PodTerminal } from '@/components/podTerminal'
import { useEffect, useState } from 'react'
import { useLocation } from 'dva'
import { wsUrl } from '../../../.././../config/ws'

interface Props {
  pod: string
  namespace: string
  command: string
}

function Index(props: Props) {
  const { pod, namespace, command } = props
  const [prop, setProp] = useState<Props>({
    pod, namespace, command
  });

  // @ts-ignore
  const { query } = useLocation()

  useEffect(() => {
    setProp({
      pod: query.pod,
      namespace: query.namespace,
      command: query.command
    })
  }, [query])

  return (
    <div>
      {
        prop.pod && <PodTerminal
          url={wsUrl}
          {...prop}
        />
      }

    </div>
  )
}

export default Index
